package demo1;

public class Test {
    //多态
   /* public static void fun(Animal animal) {
        animal.eat();//只能调用父类
        Dog dog1 = new Dog("旺财",8,"黄");
        dog1.eat();
        dog1.Age();
    }

    public static Animal fun1(){
        return new Dog("旺财",8,"黄");//向上转型的第三种方式-->返回值
    }
    public static void main(String[] args) {
        Dog dog = new Dog("旺财",8,"黄");
        *//*Animal animal =new Dog("旺财",8,"黄");
        animal.eat();*//*
        dog.eat();
        fun(dog);//向上调用

    }*/

    public static void main(String[] args) {
        Animal dog = new Dog("旺财",8,"黄");
        Bird bird = new Bird("布谷",3);
        dog.eat();//调用的是子类的方法
        bird.fly();
        bird.eat();//调用的是父类的方法

        if(dog instanceof Bird){//只能由父类定义的新成员才能这样操作
            Bird bird1 = (Bird) dog;
            bird1.fly();
        }
        else {
            System.out.println(" ");
        }
    }
}
